const startProcessMixin = {
    methods: {
        $_startProcessMixin_startProcess(canStartProcessId,buttonLoadingFunction){
            if(buttonLoadingFunction){
                buttonLoadingFunction(true)
            }
            this.axios.get(this.$baseURL.workflow + '/workflow/definition/someVersion' ,{params:{canStartProcessId: canStartProcessId}})
                .then(res=>{
                    let data = res.data
                    let formType = data.startFormType
                    switch (formType.type) {
                        case 'dynamic':{
                            this.$router.push({path: '/formDynamic', query: {processDefinitionId:data.id}})
                            break
                        }
                        case 'relation':{
                            this.$router.push({path: '/formRelation', query: {processDefinitionId:data.id}})
                            break
                        }
                        case 'normal':{
                            this.$router.push(formType.formKey)
                            break
                        }
                        default:{
                            this.$confirm('当前流程没有启动表单确定要启动吗?', '提示', {
                                type: 'warning'
                            }).then(() => {
                                if(buttonLoadingFunction){
                                    buttonLoadingFunction(true)
                                }
                                this.axios.post(this.$baseURL.workflow + '/workflow/process/startWorkflow',{processDefinitionId: data.id})
                                    .then(res => {
                                        this.$message.success('流程启动成功成功，您可以在我发起的流程中查看')
                                    })
                                    .catch(error => {
                                        if(error.response){
                                            if(error.response.status == 404){
                                                this.$message.error('数据不存在，请刷新数据再试')
                                            }else {
                                                this.$message.error(error.response.data.msg)
                                            }
                                        }else {
                                            this.$message.error('网络错误或服务不可用')
                                        }
                                    }).finally(()=>{
                                    if(buttonLoadingFunction){
                                        buttonLoadingFunction(false)
                                    }
                                })
                            }).catch(()=>{
                                if(buttonLoadingFunction){
                                    buttonLoadingFunction(false)
                                }
                            })
                        }
                    }

                })
                .catch(error=>{
                    if(error.response){
                        this.$message.error(error.response.data.msg)
                    }else {
                        this.$message.error('网络错误或服务不可用')
                    }
                }).finally(()=>{
                if(buttonLoadingFunction){
                    buttonLoadingFunction(false)
                }
            })
        }
    }
}

export default startProcessMixin